//
//  DMCCycleImages.h
//  22-AliPlanet_HomeWork
//
//  Created by dllo on 16/8/4.
//  Copyright © 2016年 DM.C. All rights reserved.
//
#import "NewSongTableViewCell.h"
#import "LittleData.h"
#import "NewSongCollecCell.h"
#import "UIImageView+DownloadImage.h"

@interface NewSongTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *layout;

@end

@implementation NewSongTableViewCell
- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    CGFloat width = (self.contentView.frame.size.width - 20) / 3;
    CGFloat height = width * 3 / 2;
    _layout.itemSize = CGSizeMake(width, height);
    _layout.minimumInteritemSpacing = 5;
    _layout.minimumLineSpacing = 5;
    _layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
    if (_data) {
        [self.collectionView reloadData];
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _data.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    NewSongCollecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"newsong" forIndexPath:indexPath];
    cell.nameLabel.text = _data[indexPath.row].name;
    cell.descLabel.text = _data[indexPath.row].desc;
    
    [cell.image asyncDownloadImageWithURL:_data[indexPath.row].picUrl completionHandler:^(NSData *data, UIImage *image) {
        
    }];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"%ld", _section_cell);
    if (_section_cell == 3) {
       NSLog(@"点击了新歌新碟的第%ld个", indexPath.row);
    } else if (_section_cell == 4) {
        NSLog(@"点击了手机唱片店的第%ld个", indexPath.row);
    } else if (_section_cell == 5) {
        NSLog(@"点击了热门歌单的第%ld个", indexPath.row);
    } else if (_section_cell == 6) {
        NSLog(@"点击了推荐艺人的第%ld个", indexPath.row);
    }
    
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
